#include "dswmessagesvr.h"

CDswmessagesvr::CDswmessagesvr(LPST_ENV_T pEnv, int nPort)
: CTcpserverbase(pEnv, nPort)
{
	LOG4CPLUS_DEBUG(log_dsw, "Create message server on port " << nPort);
}

CDswmessagesvr::~CDswmessagesvr()
{
	LOG4CPLUS_DEBUG(log_dsw, "Destroy message server!");
}

void CDswmessagesvr::OnAccept(evutil_socket_t fd, struct sockaddr *address, int socklen)
{
	char sKey[64];
	struct sockaddr_in *client = (struct sockaddr_in*)address;
	sprintf(sKey, "%s:%d", inet_ntoa(client->sin_addr), ntohs(client->sin_port));
	CDswLanMsgSession::createNew(m_pEnv, evconnlistener_get_base(m_pListener), fd, sKey);
}
